function PriorityQueue() {

  function QueueElement(element, prority) {
    this.element = element
    this.prority = prority
  }

  // 封装属性
  this.items = []

  // 1.插入方法
  PriorityQueue.prototype.enqueue = function(element, prority) {
    // 1.创建QueueElement对象
    let queueElement = new QueueElement(element, prority)
    if (this.items.length) {
      for (let i = 0; i < this.items.length; i++) {
        if (queueElement.prority > this.items[i].prority) {
          this.items.splice(i, 0, queueElement)
          break
        }
      }
    } else {
      this.items.push(queueElement)
    }
  }

  PriorityQueue.prototype.enqueueNew = function(element, prority) {
    let queueElement = new QueueElement(element, prority)
    this.items.push(queueElement)
    this.items.sort((x, y) => y.prority - x.prority)
  }

  //2.移除操作，返回被移除的项
  PriorityQueue.prototype.dequeue = function() {
    let temp = this.items[this.items.length - 1]
    this.items.length--
      return temp
  }

  // 3.返回队列的第一个元素
  PriorityQueue.prototype.front = function() {
    return this.items[this.items.length - 1]
  }

  // 4.判断队列是否为空
  PriorityQueue.prototype.isEmpty = function() {
    return this.items.length == 0
  }

  // 5.返回队列大小
  PriorityQueue.prototype.size = function() {
    return this.items.length
  }

  // 6.将队列中的内容转换为字符串
  PriorityQueue.prototype.toString = function(punctuation) {
    return this.items.map(item => item.element).join(punctuation)
  }
}


let p = new PriorityQueue()
p.enqueueNew('cuifan2', 100)
p.enqueueNew('lilizi', 200)
p.enqueueNew('cuifan2', 101)
console.log(p.items);
console.log(p.toString());